#include <stdio.h>
#include <stdint.h>
#include <pthread.h>
#include <sys/time.h>

#define UUTIL_INFO(...) fprintf(stdout, "\033[32m[UUTIL_INFO] %s(%d): \033[0m", __FUNCTION__, __LINE__),fprintf(stdout, __VA_ARGS__)
#define UUTIL_ERR(...) fprintf(stderr, "\033[31m[UUTIL_ERR] %s(%d): \033[0m", __FUNCTION__, __LINE__),fprintf(stderr, __VA_ARGS__)

void UbuntuDelayMs(uint32_t ms)
{
    struct timeval tv;
    tv.tv_sec = ms / 1000;
    tv.tv_usec = ms % 1000 * 1000;
    select(0, NULL, NULL, NULL, &tv);
}

void UbuntuNewThread(void *obj, void *(callback)(void*))
{
    pthread_t th;
    pthread_attr_t attr;
    int32_t ret;
    //禁用线程同步,线程运行结束后自动释放
    pthread_attr_init(&attr);
    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
    //抛出线程
    ret = pthread_create(&th, &attr, callback, (void *)obj);
    if (ret != 0)
        UUTIL_ERR("pthread_create failed !!\r\n");
    //attr destroy
    pthread_attr_destroy(&attr);
}
